$.ready(function()
{
	window.console = loadFirebugConsole();

	navBarUpdateLinks();

	Global.section.getCurrent(function($section, $response){
		if ( !$section )
			return;

		//section = Global.section.getName(section);

		$("#" + $section).className = "active";

		Global.loadUserScript( $response );
	});

	$.error.onerror = function(errObj, description){
		alert(description);
	};


	$("#waitPic").style.display = "none";
});

window.extend({
	reload : function()	{
		window.open(location.href, "_self");
	}
});

function navBarReset(){
	var pLink = $("#navbar a");

	pLink.walk(function(p){
		p.className = "";
	});
}

function navBarUpdate(element){
	if ( !$.isStr(element) )
		element = element.id;

	element = $("#"+ element);

	if ( !element )
		return;

	navBarReset();

	element.className = "active";

	navBarUpdateLinks();
}

function navBarUpdateLinks(element){
	var pLink = $("#navbar a");

	pLink.walk(function(p){
		p.bind("click", function(param){
			var $me = this;

			Global.section.change(this.id, function(){
				navBarUpdate($me);
			});
		});
	});
}

function LogOut(){
	Services.call("Logout", function(response){
		if ( response.confirm )
			window.reload();
	});
}
